﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using CsvHelper;

namespace ZCrawler
{
    public class CSVParser
    {
        public static void ParseFields(string csvFile, Action<Dictionary<string, string>> DumpStep, params string[] fields)
        {
            Dictionary<string, string> result = new Dictionary<string, string>();
            using (TextReader tr = new StreamReader(csvFile, Encoding.UTF8))
            {
                using (CsvReader reader = new CsvReader(tr))
                {
                    while (reader.Read())
                    {
                        result.Clear();
                        foreach (string f in fields)
                        {
                            result.Add(f, reader[f]);
                        }
                        DumpStep(result);
                    }
                }
            }
        }
    }
}
